#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
typedef pair<int,int> pii;
    int minCost(int n, vector<vector<int>>& edges) {
        vector<vector<pii>> g(n);
        for(auto& e:edges)
        {
            g[e[0]].emplace_back(e[1],e[2]);
            g[e[1]].emplace_back(e[0],e[2]*2);

        }
        vector<int> d(n,INT_MAX);
        d[0]=0;
        priority_queue<pii,vector<pii>,greater<>> q;
        q.emplace(0,0);
        while(!q.empty())
        {
            auto [d_x,x]=q.top();
            q.pop();
            if(d_x>d[x]) continue;
            for(auto& [y,d_y]:g[x])
            {
                int new_d=d_y+d_x;
                if(new_d<d[y])
                {
                    d[y]=new_d;
                    q.emplace(new_d,y);
                }
            }

        }
        return d[n-1]==INT_MAX?-1:d[n-1];
    }
};